<!DOCTYPE HTML>
<html lang="en">
<head>
<title>MouseMove - Syntax &amp; Usage | AutoHotkey</title>
<meta name="description" content="The MouseMove command moves the mouse cursor." />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
</head>
<body>

<h1>MouseMove</h1>

<p>Moves the mouse cursor.</p>

<pre class="Syntax"><span class="func">MouseMove</span>, X, Y <span class="optional">, Speed, Relative</span></pre>
<h2>Parameters</h2>
<dl>

  <dt>X, Y</dt>
  <dd><p>The x/y coordinates to move the mouse to, which can be <a href="../Variables.htm#Expressions">expressions</a>. Coordinates are relative to the active window unless <a href="CoordMode.htm">CoordMode</a> was used to change that.</p></dd>

  <dt>Speed</dt>
  <dd><p>The speed to move the mouse in the range 0 (fastest) to 100 (slowest), which can be an <a href="../Variables.htm#Expressions">expression</a>.</p>
    <p class="note"><strong>Note</strong>: A speed of 0 will move the mouse instantly.</p>
    <p>If omitted, the default speed (as set by <a href="SetDefaultMouseSpeed.htm">SetDefaultMouseSpeed</a> or 2 otherwise) will be used.</p>
      <p><em>Speed</em> is ignored for <a href="SendMode.htm">SendInput/Play modes</a>; they move the mouse instantaneously (though <a href="SetMouseDelay.htm">SetMouseDelay</a> has a mode that applies to SendPlay). To visually move the mouse more slowly -- such as a script that performs a demonstration for an audience -- use <code><a href="Send.htm#Click">SendEvent {Click 100, 200}</a></code> or <code><a href="SendMode.htm">SendMode</a> Event</code> (optionally in conjuction with <a href="BlockInput.htm">BlockInput</a>).</p></dd>

  <dt>Relative</dt>
  <dd>
    <p>If omitted, the X and Y coordinates will be treated as absolute values. To change this behavior, specify the following letter:</p>
    <p><strong>R:</strong> The X and Y coordinates will be treated as offsets from the current mouse position. In other words, the cursor will be moved from its current position by X pixels to the right (left if negative) and Y pixels down (up if negative).</p>
  </dd>

</dl>

<h2>Remarks</h2>
<p>This command uses the sending method set by <a href="SendMode.htm">SendMode</a>.</p>
<p>The <a href="SendMode.htm">SendPlay mode</a> is able to successfully generate mouse events  in a broader variety of games than the other modes. In addition, some applications and games may have trouble  tracking the mouse if it moves too quickly. The <em>speed</em> parameter or <a href="SetDefaultMouseSpeed.htm">SetDefaultMouseSpeed</a> can be used to reduce the speed (in the default <a href="SendMode.htm">SendEvent mode</a> only).</p>
<p>The <a href="BlockInput.htm">BlockInput</a> command can be used to prevent any physical mouse activity by the user from disrupting the simulated mouse events produced by the mouse commands. However, this is generally not needed for the <a href="SendMode.htm">SendInput/Play</a> modes because they automatically postpone the user's physical mouse activity until afterward.</p>
<p>There is an automatic delay after every movement of the mouse (except for <a href="SendMode.htm">SendInput mode</a>). Use <a href="SetMouseDelay.htm">SetMouseDelay</a> to change the length of the delay.</p>
<p>The following is an alternate way to move the mouse cursor that may work better in certain multi-monitor configurations:</p>
<pre><a href="DllCall.htm">DllCall</a>(&quot;SetCursorPos&quot;, &quot;int&quot;, 100, &quot;int&quot;, 400)  <em>; The first number is the X-coordinate and the second is the Y (relative to the screen).</em></pre>
<p>On a related note, the mouse cursor can be temporarily hidden via the <a href="DllCall.htm#HideCursor">hide-cursor example</a>.</p>
<h2>Related</h2>
<p><a href="CoordMode.htm">CoordMode</a>, <a href="SendMode.htm">SendMode</a>, <a href="SetDefaultMouseSpeed.htm">SetDefaultMouseSpeed</a>, <a href="SetMouseDelay.htm">SetMouseDelay</a>, <a href="Click.htm">Click</a>, <a href="MouseClick.htm">MouseClick</a>, <a href="MouseClickDrag.htm">MouseClickDrag</a>, <a href="MouseGetPos.htm">MouseGetPos</a>, <a href="BlockInput.htm">BlockInput</a></p>
<h2>Examples</h2>
<div class="ex" id="ExBasic">
<p><a href="#ExBasic">#1</a>: Move the mouse to a new position:</p>
<pre>MouseMove, 200, 100</pre>
</div>

<div class="ex" id="ExAdvanced">
<p><a href="#ExAdvanced">#2</a>: Move the mouse slowly (speed 50 vs. 2) by 20 pixels to the right and 30 pixels down from its current location:</p>
<pre>MouseMove, 20, 30, 50, R</pre>
</div>

</body>
</html>
